import json

class Student:
    def __init__(self, username, fullName, age, school, interests, relations):
        self.username = username
        self.fullName = fullName
        self.age = age
        self.school = school
        self.interests = interests
        self.relations = relations

class SocialNetwork:
    def __init__(self, students_data):
        valid_params = Student.__init__.__code__.co_varnames[1:]
        self.students = {
            student['username']: Student(**{k: v for k, v in student.items() if k in valid_params})
            for student in students_data
        }

    def get_friends(self, username):
        if username not in self.students:
            return f"Student {username} not found."
        return [self.students[friend].fullName for friend in self.students[username].relations]

    def add_friend(self, username, new_friend):
        if username not in self.students or new_friend not in self.students:
            return "Invalid username(s)"
        self.students[username].relations.append(new_friend)
        self.students[new_friend].relations.append(username)
        return "Friend added successfully"

    def filter_by_interest(self, interest):
        return [s.fullName for s in self.students.values() if interest in s.interests]

    def define_communities(self):
        communities = {}
        for student in self.students.values():
            for interest in student.interests:
                communities.setdefault(interest, []).append(student.username)
        return list(communities.items())

    def find_bridges(self):
        communities = self.define_communities()
        bridges = []
        for i in range(len(communities)):
            for j in range(i+1, len(communities)):
                common = set(communities[i][1]) & set(communities[j][1])
                if common:
                    bridges.append({
                        "communities": (communities[i][0], communities[j][0]),
                        "bridges": list(common)
                    })
        return bridges

    def get_all_users(self):
        return [
            {
                "username": student.username,
                "interests": student.interests
            }
            for student in self.students.values()
        ]